package com.io.input;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class inputStream2FileInputStream {
	public static void main(String[]args){
		File file=new File("D:\\eclipse-jee-juno-SR1-win32\\workplace\\JavaSrc\\src\\com\\io\\input\\file.txt");
		try {
			FileInputStream fin=new FileInputStream(file);
			byte[] filebt;
			try {
				filebt = readStream(fin);
				System.out.print(filebt.length);
				
				for(int i=0;i<filebt.length;i++){
					System.out.print((char)filebt[i]);
				}
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	private static byte[] readStream(FileInputStream fin) throws Exception   {
		ByteArrayOutputStream outStream=new ByteArrayOutputStream();
		byte[] buffer=new byte[1024];
		int len=-1;
		while((len=fin.read(buffer))!=-1){
			outStream.write(buffer,0,len);			
		}
		outStream.close();
		fin.close();
		return outStream.toByteArray();
	}
}
